package main

import (
	"fmt"
	"math/rand"
	"net/http"
	"time"
)

func indexHandler(w http.ResponseWriter, r *http.Request) {
	num := rand.Intn(2)
	if num == 0 {
		// 随机设置请求响应的时间
		time.Sleep(time.Second * 3)
		fmt.Fprint(w, "request slow")
		return
	}
	fmt.Fprintf(w, "quick request")
}

// server 端 搭配demo3 client来实现的案例
func main() {
	http.HandleFunc("/", indexHandler)
	err := http.ListenAndServe(":8888", nil)
	if err != nil {
		panic(err)
	}
	fmt.Println("server start success...")
}
